import localizing
import dialog
import game
from scene_handler import *
from ui import print, input, endPassage

from typing import List

class SceneType:
        """
        游戏事件类型们。
        """
        counter = 0
        def __init__(self, localize_id:str) -> None:
            self.id = SceneType.counter
            SceneType.counter += 1
            self.localize_id = localize_id
        
        def print(self, scene_name:str) -> None:
            return localizing.Localizer.I.get(self.localize_id) + " " + ":" + " " + scene_name

class SceneTypes:
    fight = SceneType("textdungeon.game.scene.type.fight")
    fightEmergency = SceneType("textdungeon.game.scene.type.fightemergency")
    fightBoss = SceneType("textdungeon.game.scene.type.fightboss")
    
    encounter = SceneType("textdungeon.game.scene.type.event")
    shop = SceneType("textdungeon.game.scene.type.shop")
    reward = SceneType("textdungeon.game.scene.type.reward")


class Scene:
    """
    游戏事件们。
    """
    def __init__(self, name:str,scene_type:SceneType, localize_id:str=None) -> None:
        self.name = name
        self.sceneType = scene_type
        self.localize_id = localize_id or name
        self.next = []
        self.pos_group = 0

    def setNext(self, next) -> None:
        self.next = next

    def choicesNextScene(self, cm: dialog.ChoiceManager) -> None:
        print(localizing.Localizer.I.get( "textdungeon.game.scene.nextscene" ).format(str( len(self.next) )))

        for index, scene in self.next:
            def _f():
                game.Game.I.status["nextScene"] = index
            cm.addChoice(dialog.Choice(scene.print(),_f))

        cm.Run()

    def print(self) -> str:
        return self.sceneType.print(localizing.Localizer.I.get(self.localize_id))
    
class RunScene:
    """
    传入一个Scene,执行。
    """
    @staticmethod
    def run(scene:Scene):
        type = scene.sceneType
        if type == SceneTypes.fight:
            Fight(scene).run()
        elif type == SceneTypes.fightBoss:
            FightBoss(scene).run()
        elif type == SceneTypes.fightEmergency:
            FightEmergency(scene).run()
        elif type == SceneTypes.encounter:
            Encounter(scene).run()
        elif type == SceneTypes.reward:
            Reward(scene).run()
        elif type == SceneTypes.shop:
            Shop(scene).run()

doImport()